package net.sudot.chess.business.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import java.time.Instant;

/**
 * 用户
 *
 * @author tangjialin on 2018-03-30.
 */
@Getter
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@SuppressWarnings("unchecked")
public abstract class User<E extends User> extends BaseEntity<E> {
    /** 用户名 */
    private String username;
    /** 密码 */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String password;
    /** 是否启用 */
    private Boolean enabled;
    /** 是否锁定 */
    private Boolean locked;
    /** 锁定日期 */
    private Instant lockDate;
    /** 最后登录IP */
    private String lastLoginIp;
    /** 最后登录日期 */
    private Instant lastLoginDate;

    public E setUsername(String username) {
        this.username = username;
        return (E) this;
    }

    public E setPassword(String password) {
        this.password = password;
        return (E) this;
    }

    public E setEnabled(Boolean enabled) {
        this.enabled = enabled;
        return (E) this;
    }

    public E setLocked(Boolean locked) {
        this.locked = locked;
        return (E) this;
    }

    public E setLockDate(Instant lockDate) {
        this.lockDate = lockDate;
        return (E) this;
    }

    public E setLastLoginIp(String lastLoginIp) {
        this.lastLoginIp = lastLoginIp;
        return (E) this;
    }

    public E setLastLoginDate(Instant lastLoginDate) {
        this.lastLoginDate = lastLoginDate;
        return (E) this;
    }
}
